home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 076-100 / disk_093 / dme / subs.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  3KB  |  157 lines

  1.  
  2. /*
  3.  *  SUBS.C
  4.  *
  5.  *    (C)Copyright 1987 by Matthew Dillon, All Rights Reserved
  6.  *
  7.  *
  8.  *  Subroutines.  Mainly workbench support stuff
  9.  */
  10.  
  11.  
  12. #include "defs.h"
  13.  
  14. makemygadget(gad)
  15. register struct Gadget *gad;
  16. {
  17.     static unsigned long ga[] = {
  18.     0x00000000,    /* 32 pixels across */
  19.     0x00FDCBFD,
  20.     0xFFFDDFFD,
  21.     0x00000000,
  22.     0x00DFDDDF,
  23.     0x00000000,
  24.     0xBC0EF00B,
  25.     0x00000000,
  26.     0xBFC00CDC,
  27.     0x00000000,
  28.     0xA00DF00F,
  29.     0x00000000,
  30.     0x00000000,
  31.  
  32.     0x00000000,
  33.     0x00FDCBFD,
  34.     0xFFFDDFFD,
  35.     0x00000000,
  36.     0x00DFDDDF,
  37.     0x00000000,
  38.     0xBC0EF00B,
  39.     0x00000000,
  40.     0xBFC00CDC,
  41.     0x00000000,
  42.     0xA00DF00F,
  43.     0x00000000,
  44.     0x00000000
  45.     };
  46.     static struct Image image = {
  47.     0, 0, 20, sizeof(ga)/4/2, 2, (APTR)ga, 3, 0, NULL
  48.     };
  49.     bzero(gad, sizeof(struct Gadget));
  50.     gad->Width = 20;
  51.     gad->Height = sizeof(ga)/4/2 + 1;
  52.     gad->Flags    = GADGIMAGE|GADGHCOMP;
  53.     gad->GadgetType   = BOOLGADGET;
  54.     gad->Activation = RELVERIFY|GADGIMMEDIATE;
  55.     gad->GadgetRender = (APTR)ℑ
  56. }
  57.  
  58. /*
  59.  * return index of first non space.  Returns 255 if no spaces found.
  60.  */
  61.  
  62. firstns(str)
  63. register char *str;
  64. {
  65.     register short i;
  66.  
  67.     for (i = 0; str[i] && str[i] == ' '; ++i);
  68.     if (str[i] == 0)
  69.     i = 0;
  70.     return(i);
  71. }
  72.  
  73. lastns(str)
  74. register char *str;
  75. {
  76.     register short i;
  77.  
  78.     for (i = strlen(str) - 1; i > 0 && str[i] == ' '; --i);
  79.     if (i < 0)
  80.     i = 0;
  81.     return(i);
  82. }
  83.  
  84. wordlen(str)
  85. register char *str;
  86. {
  87.     register short i;
  88.  
  89.     for (i = 0; *str && *str != ' '; ++i, ++str);
  90.     return(i);
  91. }
  92.  
  93. /*
  94.  *  Find the path from some root device to a specific filename (src), and
  95.  *  stick the result in (dest).  If unable to backtrace along directories,
  96.  *  simply copy (src) into (dest)
  97.  *
  98.  *  Returns (1) if able to backtrace, (0) if not.
  99.  */
  100.  
  101. getpath(src, dest)
  102. char *src, *dest;
  103. {
  104.     register long flock, pflock;
  105.     register short len, total;
  106.     register FIB *fib = (FIB *)malloc(sizeof(FIB));
  107.     char c;
  108.  
  109.     dest[0] = 0;
  110.     total = 1;
  111.     flock = Lock(src, ACCESS_READ);
  112.     if (flock == NULL) {               /* missing file?    */
  113.     for (len = strlen(src); len >= 0; --len) {
  114.         if (src[len] == '/') {
  115.         --len;
  116.         break;
  117.         }
  118.         if (src[len] == ':')
  119.         break;
  120.     }
  121.     if (c = src[len + 1]) {
  122.         strcpy(dest, src+len+2);
  123.         total = strlen(dest)+1;
  124.     }
  125.     src[len + 1] = 0;
  126.     flock = Lock(src, ACCESS_READ);
  127.     src[len + 1] = c;
  128.     }
  129.     if (flock) {
  130.     do {
  131.         pflock = ParentDir(flock);
  132.         if (Examine(flock, fib) == 0) {
  133.         puts ("Examine failed");
  134.         fib->fib_FileName[0] = 0;
  135.         }
  136.         if (fib->fib_FileName[0] == 0)
  137.         strcpy(fib->fib_FileName, "ram");
  138.         len = strlen(fib->fib_FileName);
  139.         bmov(dest, dest + len + 1, total);
  140.         dest[len] = (pflock) ? '/' : ':';
  141.         bmov(fib->fib_FileName, dest, len);
  142.         total += len + 1;
  143.         UnLock(flock);
  144.         flock = pflock;
  145.     } while(pflock);
  146.     len = strlen(dest) - 1;
  147.     if (dest[len] == '/')
  148.         dest[len] = 0;
  149.     return(1);
  150.     }
  151.     strcpy(dest, src);
  152.     return(0);
  153. }
  154.  
  155.  
  156.  
  157.